ROOT=..
PLATFORM=$(shell $(ROOT)/systype.sh)
include $(ROOT)/Make.defines.$(PLATFORM)

ifeq "$(PLATFORM)" "linux"
	ZAP = zap
else
	ZAP =
endif

# 源文件所在目录（默认当前目录）
SRC_DIR := .
# 构建输出目录（固定为源码目录下的 build）
BUILD_DIR := $(SRC_DIR)/build


PROGS =	access cdpwd changemod devrdev filetype mycd umask unlink $(ZAP) filetype_test stat
MOREPROGS = ftw8

#all:	$(PROGS) $(MOREPROGS)
all:	$(addprefix $(BUILD_DIR)/, $(PROGS)) 

$(BUILD_DIR)/%:	%.c $(LIBAPUE) $(BUILD_DIR)
	$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) $(LDLIBS)
#$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS)

$(BUILD_DIR)/ftw8:	ftw8.c $(LIBAPUE)
	$(CC) $(CFLAGS) $(NAMEMAX) ftw8.c -o $(BUILD_DIR)/ftw8 $(LDFLAGS) $(LDLIBS)

# 确保 build 目录存在（若不存在则创建）
$(BUILD_DIR):
	@mkdir -p $@
	@echo "Created build directory: $@"

clean:
	@if [ -d "$(BUILD_DIR)" ]; then \
		echo "Cleaning build directory..."; \
		rm -rf "$(BUILD_DIR)"; \
	else \
		echo "No build directory to clean."; \
	fi

#clean:
#	rm -f $(PROGS) $(MOREPROGS) $(TEMPFILES) *.o $(ZAP)

include $(ROOT)/Make.libapue.inc
